<?php

Raise::load('core.RaiseObject');
Raise::load('db.RaiseDbConnection');

/**
 * RaiseDbReader class
 * A reader for reading data from the source
 *
 * @author Sam-Mauris Yong <hellclanner at live dot com>
 * @license http://www.opensource.org/licenses/bsd-license New BSD License
 * @package Raise.Core.DataAccess
 * @since 1.2
 */
class RaiseDbReader extends RaiseObject {

    /**
     * The RaiseDbConnection assosciated with the reader
     * @var RaiseDbConnection
     */
    private $connection;

    /**
     * The current row
     * @var array|boolean
     */
    private $row;

    /**
     * Creates a new RaiseDbReader
     * @param RaiseDbConnection $conn the connection assosciated
     */
    public function __construct($conn){
        $this->connection = $conn;
    }

    /**
     * Move the internal pointer of the RaiseDbReader
     * and prepare the next row.
     *
     * @return array|boolean
     */
    public function hasNext(){
        $pool = $this->connection->adapter()->fetchRowArray();
        $this->row = $pool;
        return $pool;
    }

    /**
     * Gets the current row
     * @return array|boolean
     */
    public function getRow(){
        return $this->row;
    }

    /**
     * Gets a value in the current row
     * @param string $column Column of the value to fetch
     * @return mixed
     */
    public function getValue($column){
        return $this->row[$column];
    }
}

